<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({});
    const CommonChild = {
      template: `
        <div>
          这是子组件
          <button @click="emitMsg">向父组件通信</button>
        </div>
      `,
      data(){
        return {
          msg: '这是子组件中的数据'
        }
      },
      methods: {
        emitMsg() {
          this.$emit('biubiu', this.msg)
        }
      }
    }
    const CommonHead = {
      // 模板视图
      template: `
        <div>
          这是父组件
          {{msg}}
          <hr/>
          <common-child @biubiu="fn"></common-child>
        </div>
      `,
      data() {
        return {
          msg: ''
        }
      },
      methods: {
        fn(msg){
          console.log('我收到你的消息了', msg)
          this.msg = msg;
        }
      },
      components: {
        CommonChild
      }
    }
    app.component('CommonHead', CommonHead)

    app.mount('#app')
  </script>
</body>

</html>